package net.chengp.ms.auth.config;

import java.util.Collection;

import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2RefreshToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * JWT增强，刷新后原token得做失效处理
 * 
 * @author chengp
 *
 */
public class JwtTokenStoreEnhance extends JwtTokenStore implements TokenStore {

	public JwtTokenStoreEnhance(JwtAccessTokenConverter jwtTokenEnhancer) {
		super(jwtTokenEnhancer);
	}

	@Override
	public OAuth2Authentication readAuthentication(OAuth2AccessToken token) {
		System.out.println("------------------" + "通过token获取身份信息token");
		return super.readAuthentication(token);
	}

	@Override
	public OAuth2Authentication readAuthentication(String token) {
		System.out.println("------------------" + "通过token获取身份信息string");
		return super.readAuthentication(token);
	}

	@Override
	public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {
		System.out.println("------------------" + "存储令牌");
		super.storeAccessToken(token, authentication);
	}

	@Override
	public OAuth2AccessToken readAccessToken(String tokenValue) {
		System.out.println("------------------" + "获取令牌");
		return super.readAccessToken(tokenValue);
	}

	@Override
	public void removeAccessToken(OAuth2AccessToken token) {
		System.out.println("------------------" + "删除令牌");
		super.removeAccessToken(token);
	}

	@Override
	public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) {
		System.out.println("------------------" + "存储刷新令牌");
		super.storeRefreshToken(refreshToken, authentication);
	}

	@Override
	public OAuth2RefreshToken readRefreshToken(String tokenValue) {
		System.out.println("------------------" + "获取刷新令牌string");
		return super.readRefreshToken(tokenValue);
	}

	@Override
	public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) {
		System.out.println("------------------" + "获取刷新令牌token");
		return super.readAuthenticationForRefreshToken(token);
	}

	@Override
	public void removeRefreshToken(OAuth2RefreshToken token) {
		System.out.println("------------------" + "删除刷新令牌");
		super.removeRefreshToken(token);
	}

	@Override
	public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken) {
		System.out.println("------------------" + "使用刷新令牌删除访问令牌");
		super.removeAccessTokenUsingRefreshToken(refreshToken);
	}

	@Override
	public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) {
		System.out.println("------------------" + "使用身份信息获取令牌");
		return super.getAccessToken(authentication);
	}

	@Override
	public Collection<OAuth2AccessToken> findTokensByClientIdAndUserName(String clientId, String userName) {
		System.out.println("------------------" + "使用客户端ID和名称获取令牌");
		return super.findTokensByClientIdAndUserName(clientId, userName);
	}

	@Override
	public Collection<OAuth2AccessToken> findTokensByClientId(String clientId) {
		System.out.println("------------------" + "使用客户端ID获取令牌");
		return super.findTokensByClientId(clientId);
	}

}
